/*
 * Potrs.cs
 * 
 * Copyright (c) 2003-2004, dnAnalytics Project. All rights reserved.
*/

#if !MANAGED
using System;
using System.Runtime.InteropServices;

using dnA.Utility;

namespace dnA.Math.Lapack{
	[System.Security.SuppressUnmanagedCodeSecurityAttribute]
	internal sealed class Potrs {
		private Potrs() {}

		private static void ArgumentCheck(UpLo uplo, int n, int nrhs, object A, int lda, object B, int ldb){
			if (n<0) 
				throw new ArgumentException("n must be at least zero.");
			if (nrhs<0) 
				throw new ArgumentException("nrhs must be at least zero.");
			if (A==null) 
				throw new ArgumentNullException("A","A cannot be null.");
			if (lda<n || lda<1) 
				throw new ArgumentException("lda must be at least max(1,n)");
			if (B==null) 
				throw new ArgumentNullException("B","B cannot be null.");
			if (ldb<n || ldb<1) 
				throw new ArgumentException("ldb must be at least max(1,n)");
		}
		
		internal static int Compute( UpLo uplo, int n, int nrhs, float[] A, int lda, float[] B, int ldb  ){
			ArgumentCheck(uplo, n, nrhs, A, lda, B, ldb);
			return dna_lapack_spotrs(uplo, n, nrhs, A, lda, B, ldb);
		}

		internal static int Compute( UpLo uplo, int n, int nrhs, double[] A, int lda, double[] B, int ldb  ){
			ArgumentCheck(uplo, n, nrhs, A, lda, B, ldb);
			return dna_lapack_dpotrs(uplo, n, nrhs, A, lda, B, ldb);
		}

		internal static int Compute( UpLo uplo, int n, int nrhs, ComplexFloat[] A, int lda, ComplexFloat[] B, int ldb  ){
			ArgumentCheck(uplo, n, nrhs, A, lda, B, ldb);
			return dna_lapack_cpotrs(uplo, n, nrhs, A, lda, B, ldb);
		}

		internal static int Compute( UpLo uplo, int n, int nrhs, ComplexDouble[] A, int lda, ComplexDouble[] B, int ldb  ){
			ArgumentCheck(uplo, n, nrhs, A, lda, B, ldb);
			return dna_lapack_zpotrs(uplo, n, nrhs, A, lda, B, ldb);
		}

		[DllImport(dnA.Utility.Configuration.BLASLibrary, ExactSpelling=true, SetLastError=false)]
		private static extern int dna_lapack_spotrs( UpLo uplo, int n, int nrsh, [In,Out]float[] A, int lda, [In,Out]float[] B, int ldb );

		[DllImport(dnA.Utility.Configuration.BLASLibrary, ExactSpelling=true, SetLastError=false)]
		private static extern int dna_lapack_dpotrs( UpLo uplo, int n, int nrsh, [In,Out]double[] A, int lda, [In,Out]double[] B, int ldb );

		[DllImport(dnA.Utility.Configuration.BLASLibrary, ExactSpelling=true, SetLastError=false)]
		private static extern int dna_lapack_cpotrs( UpLo uplo, int n, int nrsh, [In,Out]ComplexFloat[] A, int lda, [In,Out]ComplexFloat[] B, int ldb );

		[DllImport(dnA.Utility.Configuration.BLASLibrary, ExactSpelling=true, SetLastError=false)]
		private static extern int dna_lapack_zpotrs( UpLo uplo, int n, int nrsh, [In,Out]ComplexDouble[] A, int lda, [In,Out]ComplexDouble[] B, int ldb );
	}
}
#endif